const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/playground', {useUnifiedTopology: true, useNewUrlParser: true})
        .then(()=>console.log('数据库连接成功'))
        .catch(err => console.log('数据库连接失败',err))
const courseSchema = mongoose.Schema({
    name: String,
    author: String,
    isPublished: Boolean
});
const Course = mongoose.model('Course',courseSchema);

Course.create({
    name : 'JavaScript',
    author: 'ithema',
    isPublished: true
}/*,(err,result)=>{
    console.log(err)
    console.log(result)
}*/).then(doc => console.log(doc)).catch(err => console.log(err))
/*
const course = new Course({
    name : 'node.js',
    author: 'ithema',
    isPublished: true
});
course.save();*/
